<?php
/*******************************************************************************

    FinalsClub.org is a platform for students and faculty to collaborate
    and share their knowledge with the world.

    Copyright (C) 2009  Andrew Magliozzi
 
    This file is a part of FinalsClub.org.

    FinalsClub.org is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
    To contact FinalsClub.org, send an email to info@finalsclub.org, or
    send mail to Finals Club, c/o Veritas Tutors, 1132 Massachusetts Avenue,
    Cambridge, MA 02138.

*******************************************************************************/

/**
 * Task form.
 *
 * @package    FinalsClub
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class TaskForm extends BaseTaskForm {
	
	public function configure() {
		
		// retrieve all the task lists
		$taskLists = TaskListPeer::retrieveByGroupId($this->getOption('group_id'));
		$taskListChoices = array();
		foreach($taskLists as $taskList) {
			$taskListChoices[$taskList->getId()] = $taskList->getName();
		}		
		$this->widgetSchema['task_list_id'] = new sfWidgetFormSelect(
			array('choices' => $taskListChoices)
		);
		$this->validatorSchema['task_list_id'] = new sfValidatorInteger(array('required' => true),
			array('required' => 'You must select or create a task list before creating a task.')
		);
		
		// retrieve all members of this group
		$groupMembers = GroupMemberPeer::retrieveByGroupId($this->getOption('group_id'));
		$memberChoices = array();
		foreach($groupMembers as $member) {
			$memberChoices[$member->getUser()->getId()] = $member->getUser()->getFullName();
		}
		$this->widgetSchema['user_id'] = new sfWidgetFormSelect(
			array('choices' => $memberChoices)
		);
		$this->validatorSchema['user_id'] = new sfValidatorPass();
		
		$this->widgetSchema['creator_id'] = new sfWidgetFormInputHidden();
		$this->validatorSchema['creator_id'] = new sfValidatorPass();
		
		$this->widgetSchema['course_id'] = new sfWidgetFormInputHidden();
		$this->validatorSchema['course_id'] = new sfValidatorPass();
		
		$this->widgetSchema['group_id'] = new sfWidgetFormInputHidden();
		$this->validatorSchema['group_id'] = new sfValidatorPass();
		$this->setDefault('group_id', $this->getOption('group_id'));
		
		$this->widgetSchema['type'] = new sfWidgetFormInputHidden();
		$this->validatorSchema['type'] = new sfValidatorPass();
		
		$this->widgetSchema['type_id'] = new sfWidgetFormInputHidden();
		$this->validatorSchema['type_id'] = new sfValidatorPass();

		$this->widgetSchema['resource'] = new sfWidgetFormInputHidden();
		$this->validatorSchema['resource'] = new sfValidatorPass();
		
		$this->widgetSchema['resource_id'] = new sfWidgetFormInputHidden();
		$this->validatorSchema['resource_id'] = new sfValidatorPass();
		
		$this->widgetSchema['url'] = new sfWidgetFormInput();
		$this->validatorSchema['url'] = new sfValidatorString(array('required' => false), array('max_length' => 155));
		
		$this->widgetSchema['url_title'] = new sfWidgetFormInput();
		$this->validatorSchema['url_title'] = new sfValidatorString(array('required' => false), array('max_length' => 15));
		
		$this->setDefault('due_date', time());
		
		$this->validatorSchema['name'] = new sfValidatorString(array('max_length' => 80, 'required' => true), 
			array('required' => 'Please enter a name for this task')
		);
		
		$this->validatorSchema->setOption('allow_extra_fields', true);
	}
}
